#include <string>
#include "sizedialog.h"

using namespace std;

template <typename T> string toStr(T tmp);
template <typename T> T strTo(string tmp);


SizeDialog::SizeDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade)
	: Gtk::Dialog(cobject) {
	refGlade->get_widget("togglebutton_lockratio", togglebutton_lockratio_);
	togglebutton_lockratio_->signal_clicked().connect(sigc::mem_fun(*this, &SizeDialog::on_togglebutton_lockratio_clicked));

	refGlade->get_widget("button_ok", button_ok_);
	button_ok_->signal_clicked().connect(sigc::mem_fun(*this, &SizeDialog::on_button_ok_clicked));

	refGlade->get_widget("entry_width", entry_width_);
	entry_width_->signal_insert_at_cursor().connect(sigc::mem_fun(*this, &SizeDialog::on_entry_width_insert));
	refGlade->get_widget("entry_height", entry_height_);
	entry_height_->signal_insert_at_cursor().connect(sigc::mem_fun(*this, &SizeDialog::on_entry_height_insert));
	
	//ratio_ = 1;
}

void SizeDialog::setFractal(Fractal* fractal) {
	fractal_ = fractal;
	entry_width_->set_text(toStr(fractal->getW()).c_str());
	entry_height_->set_text(toStr(fractal->getH()).c_str());
	//ratio_ = fractal->getW() / fractal->getH();
}

void SizeDialog::on_togglebutton_lockratio_clicked() {
	
}

void SizeDialog::on_entry_width_insert(const Glib::ustring& str) {

}

void SizeDialog::on_entry_height_insert(const Glib::ustring& str) {
	
}

void SizeDialog::on_button_ok_clicked() {
	fractal_->setW(strTo<int>(string(entry_width_->get_text())));
	fractal_->setH(strTo<int>(string(entry_height_->get_text())));
	//display_->updateFractal();
}


template <typename T> string toStr(T tmp) {
    ostringstream out;
    out << tmp;
    return out.str();
}


template <typename T> T strTo(string tmp) {
    T output;
    istringstream in(tmp);
    in >> output;
    return output;
}
